<template>
<view>
<template name="el">
  <block v-if="n.name=='img'">
    <image v-if="(opts[1]&&!ctrl[i])||ctrl[i]<0" class="_img" :style="n.attrs.style" :src="ctrl[i]<0?opts[2]:opts[1]" mode="widthFix"></image>
    <image :id="n.attrs.id" :class="'_img ' + n.attrs.class" :style="(ctrl[i]==-1?'display:none;':'') + 'width:' + ctrl[i]||1 + 'px;height:1px;' + n.attrs.style" :src="n.attrs.src" :mode="n.h?'':'widthFix'" :lazy-load="opts[0]" :webp="n.webp" :show-menu-by-longpress="opts[3]&&!n.attrs.ignore" :data-i="i" @load="imgLoad" @error="mediaError" @tap.stop="imgTap" @longpress="noop"></image>
  </block><text v-else-if="n.type=='text'" :user-select="n.us" decode>{{n.text}}</text><text v-else-if="n.name=='br'">\n</text>
  <view v-else-if="n.name=='a'" :id="n.attrs.id" :class="(n.attrs.href?'_a ':'') + '' + n.attrs.class" hover-class="_hover" :style="'display:inline;' + n.attrs.style" :data-i="i" @tap.stop="linkTap">
    <node :childs="n.children" :opts="opts" style="display:inherit"></node>
  </view><video v-else-if="n.name=='video'" :id="n.attrs.id" :class="n.attrs.class" :style="n.attrs.style" :autoplay="n.attrs.autoplay" :controls="n.attrs.controls" :loop="n.attrs.loop" :muted="n.attrs.muted" :poster="n.attrs.poster" :src="n.src[ctrl[i]||0]" :data-i="i" @play="play" @error="mediaError"></video><audio v-else-if="n.name=='audio'" :id="n.attrs.id" :class="n.attrs.class" :style="n.attrs.style" :author="n.attrs.author" :controls="n.attrs.controls" :loop="n.attrs.loop" :name="n.attrs.name" :poster="n.attrs.poster" :src="n.src[ctrl[i]||0]" :data-i="i" @play="play" @error="mediaError"></audio>
  <rich-text v-else :id="n.attrs.id" :style="n.f" :nodes="[n]"></rich-text>
</template>
<block v-for="(n1, i1) in childs" :key="i1"><block data-type="template" data-is="el" data-attr="n:n1,i:''+i1,opts:opts,ctrl:ctrl" v-if="use(n1)">
  <block v-if="n5.name == 'img'">
    <image v-if="(opts[1]&&!ctrl[i])||ctrl[i]<0" class="_img" :style="n5.attrs.style" :src="ctrl[i]<0?opts[2]:opts[1]" mode="widthFix"></image>
    <image :id="n5.attrs.id" :class="'_img ' + n5.attrs.class" :style="(ctrl[i] == -1 ? 'display:none' : '') + 'width:' + ctrl[i] || 1 + 'pxheight:1px' + n5.attrs.style" :src="n5.attrs.src" :mode="n5.h ? '' : 'widthFix'" :lazy-load="opts[0]" :webp="n5.webp" :show-menu-by-longpress="opts[3] && !n5.attrs.ignore" :data-i="i1+'_'+i2+'_'+i3+'_'+i4+'_'+i5" @load="imgLoad" @error="mediaError" @tap.stop="imgTap" @longpress="noop"></image>
  </block><text v-else-if="n5.type == 'text'" :user-select="n5.us" decode>{{n5.text}}</text><text v-else-if="n5.name == 'br'">\n</text>
  <view v-else-if="n5.name == 'a'" :id="n5.attrs.id" :class="(n5.attrs.href ? '_a ' : '') + '' + n5.attrs.class" hover-class="_hover" :style="'display:inline' + n5.attrs.style" :data-i="i1+'_'+i2+'_'+i3+'_'+i4+'_'+i5" @tap.stop="linkTap">
    <node :childs="n5.children" :opts="opts" style="display:inherit"></node>
  </view><video v-else-if="n5.name == 'video'" :id="n5.attrs.id" :class="n5.attrs.class" :style="n5.attrs.style" :autoplay="n5.attrs.autoplay" :controls="n5.attrs.controls" :loop="n5.attrs.loop" :muted="n5.attrs.muted" :poster="n5.attrs.poster" :src="n5.src[ctrl[i] || 0]" :data-i="i1+'_'+i2+'_'+i3+'_'+i4+'_'+i5" @play="play" @error="mediaError"></video><audio v-else-if="n5.name == 'audio'" :id="n5.attrs.id" :class="n5.attrs.class" :style="n5.attrs.style" :author="n5.attrs.author" :controls="n5.attrs.controls" :loop="n5.attrs.loop" :name="n5.attrs.name" :poster="n5.attrs.poster" :src="n5.src[ctrl[i] || 0]" :data-i="i1+'_'+i2+'_'+i3+'_'+i4+'_'+i5" @play="play" @error="mediaError"></audio>
  <rich-text v-else :id="n5.attrs.id" :style="n5.f" :nodes="[n]"></rich-text>
</block>
  <view v-else :id="n1.attrs.id" :class="'_' + n1.name + ' ' + n1.attrs.class" :style="n1.attrs.style">
    <block v-for="(n2, i2) in n1.children" :key="i2"><block data-type="template" data-is="el" data-attr="n:n2,i:i1+'_'+i2,opts:opts,ctrl:ctrl" v-if="use(n2)">
  <block v-if="n5.name == 'img'">
    <image v-if="(opts[1]&&!ctrl[i])||ctrl[i]<0" class="_img" :style="n5.attrs.style" :src="ctrl[i]<0?opts[2]:opts[1]" mode="widthFix"></image>
    <image :id="n5.attrs.id" :class="'_img ' + n5.attrs.class" :style="(ctrl[i] == -1 ? 'display:none' : '') + 'width:' + ctrl[i] || 1 + 'pxheight:1px' + n5.attrs.style" :src="n5.attrs.src" :mode="n5.h ? '' : 'widthFix'" :lazy-load="opts[0]" :webp="n5.webp" :show-menu-by-longpress="opts[3] && !n5.attrs.ignore" :data-i="i1+'_'+i2+'_'+i3+'_'+i4+'_'+i5" @load="imgLoad" @error="mediaError" @tap.stop="imgTap" @longpress="noop"></image>
  </block><text v-else-if="n5.type == 'text'" :user-select="n5.us" decode>{{n5.text}}</text><text v-else-if="n5.name == 'br'">\n</text>
  <view v-else-if="n5.name == 'a'" :id="n5.attrs.id" :class="(n5.attrs.href ? '_a ' : '') + '' + n5.attrs.class" hover-class="_hover" :style="'display:inline' + n5.attrs.style" :data-i="i1+'_'+i2+'_'+i3+'_'+i4+'_'+i5" @tap.stop="linkTap">
    <node :childs="n5.children" :opts="opts" style="display:inherit"></node>
  </view><video v-else-if="n5.name == 'video'" :id="n5.attrs.id" :class="n5.attrs.class" :style="n5.attrs.style" :autoplay="n5.attrs.autoplay" :controls="n5.attrs.controls" :loop="n5.attrs.loop" :muted="n5.attrs.muted" :poster="n5.attrs.poster" :src="n5.src[ctrl[i] || 0]" :data-i="i1+'_'+i2+'_'+i3+'_'+i4+'_'+i5" @play="play" @error="mediaError"></video><audio v-else-if="n5.name == 'audio'" :id="n5.attrs.id" :class="n5.attrs.class" :style="n5.attrs.style" :author="n5.attrs.author" :controls="n5.attrs.controls" :loop="n5.attrs.loop" :name="n5.attrs.name" :poster="n5.attrs.poster" :src="n5.src[ctrl[i] || 0]" :data-i="i1+'_'+i2+'_'+i3+'_'+i4+'_'+i5" @play="play" @error="mediaError"></audio>
  <rich-text v-else :id="n5.attrs.id" :style="n5.f" :nodes="[n]"></rich-text>
</block>
      <view v-else :id="n2.attrs.id" :class="'_' + n2.name + ' ' + n2.attrs.class" :style="n2.attrs.style">
        <block v-for="(n3, i3) in n2.children" :key="i3"><block data-type="template" data-is="el" data-attr="n:n3,i:i1+'_'+i2+'_'+i3,opts:opts,ctrl:ctrl" v-if="use(n3)">
  <block v-if="n5.name == 'img'">
    <image v-if="(opts[1]&&!ctrl[i])||ctrl[i]<0" class="_img" :style="n5.attrs.style" :src="ctrl[i]<0?opts[2]:opts[1]" mode="widthFix"></image>
    <image :id="n5.attrs.id" :class="'_img ' + n5.attrs.class" :style="(ctrl[i] == -1 ? 'display:none' : '') + 'width:' + ctrl[i] || 1 + 'pxheight:1px' + n5.attrs.style" :src="n5.attrs.src" :mode="n5.h ? '' : 'widthFix'" :lazy-load="opts[0]" :webp="n5.webp" :show-menu-by-longpress="opts[3] && !n5.attrs.ignore" :data-i="i1+'_'+i2+'_'+i3+'_'+i4+'_'+i5" @load="imgLoad" @error="mediaError" @tap.stop="imgTap" @longpress="noop"></image>
  </block><text v-else-if="n5.type == 'text'" :user-select="n5.us" decode>{{n5.text}}</text><text v-else-if="n5.name == 'br'">\n</text>
  <view v-else-if="n5.name == 'a'" :id="n5.attrs.id" :class="(n5.attrs.href ? '_a ' : '') + '' + n5.attrs.class" hover-class="_hover" :style="'display:inline' + n5.attrs.style" :data-i="i1+'_'+i2+'_'+i3+'_'+i4+'_'+i5" @tap.stop="linkTap">
    <node :childs="n5.children" :opts="opts" style="display:inherit"></node>
  </view><video v-else-if="n5.name == 'video'" :id="n5.attrs.id" :class="n5.attrs.class" :style="n5.attrs.style" :autoplay="n5.attrs.autoplay" :controls="n5.attrs.controls" :loop="n5.attrs.loop" :muted="n5.attrs.muted" :poster="n5.attrs.poster" :src="n5.src[ctrl[i] || 0]" :data-i="i1+'_'+i2+'_'+i3+'_'+i4+'_'+i5" @play="play" @error="mediaError"></video><audio v-else-if="n5.name == 'audio'" :id="n5.attrs.id" :class="n5.attrs.class" :style="n5.attrs.style" :author="n5.attrs.author" :controls="n5.attrs.controls" :loop="n5.attrs.loop" :name="n5.attrs.name" :poster="n5.attrs.poster" :src="n5.src[ctrl[i] || 0]" :data-i="i1+'_'+i2+'_'+i3+'_'+i4+'_'+i5" @play="play" @error="mediaError"></audio>
  <rich-text v-else :id="n5.attrs.id" :style="n5.f" :nodes="[n]"></rich-text>
</block>
          <view v-else :id="n3.attrs.id" :class="'_' + n3.name + ' ' + n3.attrs.class" :style="n3.attrs.style">
            <block v-for="(n4, i4) in n3.children" :key="i4"><block data-type="template" data-is="el" data-attr="n:n4,i:i1+'_'+i2+'_'+i3+'_'+i4,opts:opts,ctrl:ctrl" v-if="use(n4)">
  <block v-if="n5.name == 'img'">
    <image v-if="(opts[1]&&!ctrl[i])||ctrl[i]<0" class="_img" :style="n5.attrs.style" :src="ctrl[i]<0?opts[2]:opts[1]" mode="widthFix"></image>
    <image :id="n5.attrs.id" :class="'_img ' + n5.attrs.class" :style="(ctrl[i] == -1 ? 'display:none' : '') + 'width:' + ctrl[i] || 1 + 'pxheight:1px' + n5.attrs.style" :src="n5.attrs.src" :mode="n5.h ? '' : 'widthFix'" :lazy-load="opts[0]" :webp="n5.webp" :show-menu-by-longpress="opts[3] && !n5.attrs.ignore" :data-i="i1+'_'+i2+'_'+i3+'_'+i4+'_'+i5" @load="imgLoad" @error="mediaError" @tap.stop="imgTap" @longpress="noop"></image>
  </block><text v-else-if="n5.type == 'text'" :user-select="n5.us" decode>{{n5.text}}</text><text v-else-if="n5.name == 'br'">\n</text>
  <view v-else-if="n5.name == 'a'" :id="n5.attrs.id" :class="(n5.attrs.href ? '_a ' : '') + '' + n5.attrs.class" hover-class="_hover" :style="'display:inline' + n5.attrs.style" :data-i="i1+'_'+i2+'_'+i3+'_'+i4+'_'+i5" @tap.stop="linkTap">
    <node :childs="n5.children" :opts="opts" style="display:inherit"></node>
  </view><video v-else-if="n5.name == 'video'" :id="n5.attrs.id" :class="n5.attrs.class" :style="n5.attrs.style" :autoplay="n5.attrs.autoplay" :controls="n5.attrs.controls" :loop="n5.attrs.loop" :muted="n5.attrs.muted" :poster="n5.attrs.poster" :src="n5.src[ctrl[i] || 0]" :data-i="i1+'_'+i2+'_'+i3+'_'+i4+'_'+i5" @play="play" @error="mediaError"></video><audio v-else-if="n5.name == 'audio'" :id="n5.attrs.id" :class="n5.attrs.class" :style="n5.attrs.style" :author="n5.attrs.author" :controls="n5.attrs.controls" :loop="n5.attrs.loop" :name="n5.attrs.name" :poster="n5.attrs.poster" :src="n5.src[ctrl[i] || 0]" :data-i="i1+'_'+i2+'_'+i3+'_'+i4+'_'+i5" @play="play" @error="mediaError"></audio>
  <rich-text v-else :id="n5.attrs.id" :style="n5.f" :nodes="[n]"></rich-text>
</block>
              <view v-else :id="n4.attrs.id" :class="'_' + n4.name + ' ' + n4.attrs.class" :style="n4.attrs.style">
                <block v-for="(n5, i5) in n4.children" :key="i5"><block data-type="template" data-is="el" data-attr="n:n5,i:i1+'_'+i2+'_'+i3+'_'+i4+'_'+i5,opts:opts,ctrl:ctrl" v-if="use(n5)">
  <block v-if="n5.name == 'img'">
    <image v-if="(opts[1]&&!ctrl[i])||ctrl[i]<0" class="_img" :style="n5.attrs.style" :src="ctrl[i]<0?opts[2]:opts[1]" mode="widthFix"></image>
    <image :id="n5.attrs.id" :class="'_img ' + n5.attrs.class" :style="(ctrl[i] == -1 ? 'display:none' : '') + 'width:' + ctrl[i] || 1 + 'pxheight:1px' + n5.attrs.style" :src="n5.attrs.src" :mode="n5.h ? '' : 'widthFix'" :lazy-load="opts[0]" :webp="n5.webp" :show-menu-by-longpress="opts[3] && !n5.attrs.ignore" :data-i="i1+'_'+i2+'_'+i3+'_'+i4+'_'+i5" @load="imgLoad" @error="mediaError" @tap.stop="imgTap" @longpress="noop"></image>
  </block><text v-else-if="n5.type == 'text'" :user-select="n5.us" decode>{{n5.text}}</text><text v-else-if="n5.name == 'br'">\n</text>
  <view v-else-if="n5.name == 'a'" :id="n5.attrs.id" :class="(n5.attrs.href ? '_a ' : '') + '' + n5.attrs.class" hover-class="_hover" :style="'display:inline' + n5.attrs.style" :data-i="i1+'_'+i2+'_'+i3+'_'+i4+'_'+i5" @tap.stop="linkTap">
    <node :childs="n5.children" :opts="opts" style="display:inherit"></node>
  </view><video v-else-if="n5.name == 'video'" :id="n5.attrs.id" :class="n5.attrs.class" :style="n5.attrs.style" :autoplay="n5.attrs.autoplay" :controls="n5.attrs.controls" :loop="n5.attrs.loop" :muted="n5.attrs.muted" :poster="n5.attrs.poster" :src="n5.src[ctrl[i] || 0]" :data-i="i1+'_'+i2+'_'+i3+'_'+i4+'_'+i5" @play="play" @error="mediaError"></video><audio v-else-if="n5.name == 'audio'" :id="n5.attrs.id" :class="n5.attrs.class" :style="n5.attrs.style" :author="n5.attrs.author" :controls="n5.attrs.controls" :loop="n5.attrs.loop" :name="n5.attrs.name" :poster="n5.attrs.poster" :src="n5.src[ctrl[i] || 0]" :data-i="i1+'_'+i2+'_'+i3+'_'+i4+'_'+i5" @play="play" @error="mediaError"></audio>
  <rich-text v-else :id="n5.attrs.id" :style="n5.f" :nodes="[n]"></rich-text>
</block>
                  <node v-else :id="n5.attrs.id" :class="'_' + n5.name + ' ' + n5.attrs.class" :style="n5.attrs.style" :childs="n5.children" :opts="opts"></node>
                </block>
              </view>
            </block>
          </view>
        </block>
      </view>
    </block>
  </view>
</block>
</view>
</template>

<script module="use" lang="wxs" src="./use.wxs"></script>

<script>
"use strict";
function t(t, r, i) {
  return r in t ? Object.defineProperty(t, r, {
    value: i,
    enumerable: !0,
    configurable: !0,
    writable: !0
  }) : t[r] = i, t;
}
// import node from "./node";

export default {
  data() {
    return {
      ctrl: {},
      i: ""
    };
  },

  components: {
    node
  },
  props: {
    childs: Array,
    opts: Array
  },
  beforeMount: function () {
    this.$emit("add", {
      detail: this
    }, {
      bubbles: !0,
      composed: !0
    });
  },
  methods: {
    noop: function () {},
    getNode: function (t) {
      for (var r = t.split("_"), i = this.childs[r[0]], e = 1; e < r.length; e++) i = i.children[r[e]];

      return i;
    },
    play: function (t) {
      if (this.root.data.pauseVideo) {
        for (var r = !1, i = t.target.id, e = this.root._videos.length; e--;) this.root._videos[e].id == i ? r = !0 : this.root._videos[e].pause();

        if (!r) {
          var o = uni.createVideoContext(i, this);
          o.id = i, this.root._videos.push(o);
        }
      }
    },
    imgTap: function (t) {
      var r = this.getNode(t.target.dataset.i);
      if (r.a) return this.linkTap(r.a);

      if (!r.attrs.ignore && (this.root.$emit("imgtap", {
        detail: r.attrs
      }), this.root.data.previewImg)) {
        var i = this.root.imgList[r.i];
        uni.previewImage({
          current: i,
          urls: this.root.imgList
        });
      }
    },
    imgLoad: function (r) {
      var i,
          e = r.target.dataset.i,
          o = this.getNode(e);
      o.w ? (this.opts[1] && !this.ctrl[e] || -1 == this.ctrl[e]) && (i = 1) : i = r.detail.width, i && this.setData(t({}, "ctrl." + e, i));
    },
    linkTap: function (t) {
      var r = t.currentTarget ? this.getNode(t.currentTarget.dataset.i).attrs : t,
          i = r.href;
      this.root.$emit("linktap", {
        detail: r
      }), i && ("#" == i[0] ? this.root.navigateTo(i.substring(1)).catch(function () {}) : i.includes("://") ? this.root.data.copyLink && uni.setClipboardData({
        data: i,
        success: function () {
          return uni.showToast({
            title: "链接已复制"
          });
        }
      }) : uni.navigateTo({
        url: i,
        fail: function () {
          uni.switchTab({
            url: i,
            fail: function () {}
          });
        }
      }));
    },
    mediaError: function (r) {
      var i = r.target.dataset.i,
          e = this.getNode(i);

      if ("video" == e.name || "audio" == e.name) {
        var o = (this.ctrl[i] || 0) + 1;
        if (o > e.src.length && (o = 0), o < e.src.length) return this.setData(t({}, "ctrl." + i, o));
      } else "img" == e.name && this.opts[2] && this.setData(t({}, "ctrl." + i, -1));

      this.root && this.root.$emit("error", {
        detail: {
          source: e.name,
          attrs: e.attrs,
          errMsg: r.detail.errMsg
        }
      });
    }
  }
};
</script>
<style>
._a{padding:1.5px 0 1.5px 0;color:#366092;word-break:break-all}._hover{text-decoration:underline;opacity:.7}._img{max-width:100%;-webkit-touch-callout:none}._b,._strong{font-weight:700}._code{font-family:monospace}._del{text-decoration:line-through}._em,._i{font-style:italic}._h1{font-size:2em}._h2{font-size:1.5em}._h3{font-size:1.17em}._h5{font-size:.83em}._h6{font-size:.67em}._h1,._h2,._h3,._h4,._h5,._h6{display:block;font-weight:700}._ins{text-decoration:underline}._li{display:list-item}._ol{list-style-type:decimal}._ol,._ul{display:block;padding-left:40px;margin:1em 0}._q::before{content:'"'}._q::after{content:'"'}._sub{font-size:smaller;vertical-align:sub}._sup{font-size:smaller;vertical-align:super}._tbody,._tfoot,._thead{display:table-row-group}._tr{display:table-row}._td,._th{display:table-cell;vertical-align:middle}._th{font-weight:700;text-align:center}._ul{list-style-type:disc}._ul ._ul{margin:0;list-style-type:circle}._ul ._ul ._ul{list-style-type:square}._abbr,._b,._code,._del,._em,._i,._ins,._label,._q,._span,._strong,._sub,._sup{display:inline}._blockquote,._div,._p{display:block}
</style>